import request from '@/utils/request';


export function getUserInfo(){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/getUserInfo',
    method:'post'
  })
}

//通过RequestId验证短信验证码的正确性
export function calcSMS(RequestId,code){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/calcSMS',
    method:'post',
    data:{
      RequestId:RequestId,
      code:code
    }
  })
}



//登录
export function Login(FormData){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/Login',
    method:'post',
    data:FormData,
    //密码可能有特殊符号 需要转码
    // transformRequest: [
    //   function (data) {
    //     let PAYLOAD = {};
    //      for (let it in data) {
    //       PAYLOAD[encodeURIComponent(it)]=encodeURIComponent(data[it]);
    //      }

    //      let jsondata = JSON.stringify(PAYLOAD);
    //      console.log(jsondata);
    //      return jsondata;
    //   }
    // ],
  })
}




//注册
export function register(FormData){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/register',
    method:'post',
    data:FormData,
    //传递base64 需要转码
    
  })
}

//手机号是否已被占用
export function phoneused(phone){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/phoneused',
    method:'post',
    data:{
      phone:phone
    }
  })
}

export function sendSMS(phone){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/sendSMS',
    method:'post',
    data:{
      phone:phone
    }
  })
}

export function checkUsername(name){
  return request({
    headers: {
      'Content-Type': 'application/json'
    },
    url:'/api/checkUsername',
    method:'get',
    params:{
      username:name,
    },
  })
}